/**
 * 文件名：ResourceController.java
 *
 * 创建人：Fyh - 1009173473@qq.com
 *
 * 创建时间：2019年1月11日 下午2:11:59
 *
 * 版权所有：南京植百汇智能科技服务有限公司
 */
package com.z100h.supplychain.core.biz.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.z100h.supplychain.core.biz.entity.ResourceDetail;
import com.z100h.supplychain.core.biz.facade.ResourceFacade;

/**
 * [描述信息：说明类的基本功能]
 *
 * @author Fyh - 1009173473@qq.com
 * @version 1.0 Created on 2019年1月11日 下午2:11:59
 */
@Controller
@RequestMapping(value = "${adminPath}/resource")
public class ResourceController extends BaseController {

	@Autowired
	private ResourceFacade resourceFacade;

	@ModelAttribute
	public ResourceDetail get(@RequestParam(required = false) String id) {
		ResourceDetail entity = null;
		if (StringUtils.isNotBlank(id)) {
			entity = new ResourceDetail();
		}
		if (entity == null) {
			entity = new ResourceDetail();
		}
		return entity;
	}

	/**
	 * 
	 * 查询sku信息
	 * 
	 * @param resourceDetail
	 * @param request
	 * @param response
	 * @param model
	 * @param ids
	 * @return
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年1月30日 下午4:13:22
	 */
	@RequestMapping(value = "findResourceDetailByIds")
	@ResponseBody
	public Map<String, Object> findResourceDetailByIds(ResourceDetail resourceDetail, HttpServletRequest request,
			HttpServletResponse response, Model model,
			@RequestParam(value = "ids", required = false) List<String> ids) {
		List<ResourceDetail> list = resourceFacade.findResourceDetailByIds(ids);
		Page<ResourceDetail> page = new Page<ResourceDetail>(request, response);
		resourceDetail.setPage(page);
		page.setList(list);
		return getBootstrapData(page);
	}

	@RequestMapping(value = { "list", "" })
	public String list() {
		return "supplychain/resource/resourceList";
	}

	/**
	 * 
	 * 查询资源sku数量
	 * 
	 * @param ids
	 * @return
	 * @author: Fyh - 1009173473@qq.com 
	 * @date: Created on 2019年1月30日 下午4:13:08
	 */
	@RequestMapping(value = "findResourceCountByIds")
	@ResponseBody
	public JSONObject findResourceCountByIds(@RequestParam(value = "ids", required = false) List<String> ids) {
		return resourceFacade.findResourceCountByIds(ids);
	}

	/**
	 * 资源列表数据
	 */
	@ResponseBody
	@RequestMapping(value = "data")
	public Map<String, Object> data(ResourceDetail resourceDetail, HttpServletRequest request,
			HttpServletResponse response, Model model) {
		Page<ResourceDetail> page = resourceFacade.findResourceDetailList(new Page<ResourceDetail>(request, response),
				resourceDetail);
		return getBootstrapData(page);
	}

	/**
	 * 校验出库单 resIds
	 * @param resourceDetail
	 * @param request
	 * @param response
	 * @param model
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "checkResourceIdsByStockOut")
	@ResponseBody
	public Map<String, Object> checkResourceIdsByStockOut(ResourceDetail resourceDetail, HttpServletRequest request,
			HttpServletResponse response, Model model,
			@RequestParam(value = "ids", required = false) List<String> ids) {
		List<ResourceDetail> list = resourceFacade.findResourceDetailByIds(ids);
		Page<ResourceDetail> page = new Page<ResourceDetail>(request, response);
		resourceDetail.setPage(page);
		page.setList(list);
		return getBootstrapData(page);
	}

	@RequestMapping(value = "timeAxis")
	public String timeAxis(HttpServletRequest request, String id) {
		request.setAttribute("id", id);
		return "supplychain/timeAxis/timeAxis";
	}

}
